package de.tum.in.softwareengineering1.ws201112.team11.sudoku.game;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import de.tum.in.softwareengineering1.ws201112.team11.sudoku.logic.SudokuGenerator;
import de.tum.in.softwareengineering1.ws201112.team11.sudoku.util.Constants;

public class SudokuGame {

	private List<Integer>	allowedChars;
	private Integer[][]		field;

	public SudokuGame() {
		field = new Integer[Constants.FIELD_LENGTH][Constants.FIELD_HEIGHT];
		allowedChars = new ArrayList<Integer>();

		for (int i = 1; i <= Constants.FIELD_LENGTH; i++) {
			allowedChars.add(i);
		}
	}

	public Integer[][] getField() {
		return field;
	}

	public void setField(Integer[][] field) {
		this.field = field;
	}

	public void setValue(int x_index, int y_index, int value) {
		field[x_index][y_index] = value;
	}

	public Integer getValue(int x_index, int y_index) {
		return field[x_index][y_index];
	}

	public List<Integer> getAllowedRemainingInRow(int row_index) throws Exception {

		if (row_index >= Constants.FIELD_LENGTH) {
			throw new Exception();
		}

		for (int i = 0; i < Constants.FIELD_LENGTH; i++) {
			
			System.out.print(field[i][row_index]+" ");
		}
		System.out.println("\n-----");
		return null;

	}
	
	public List<Integer> getAllowedRemainingInColumn(int col_index) throws Exception {

		List<Integer> allowed = new ArrayList<Integer>();
		
		if (col_index >= Constants.FIELD_HEIGHT) {
			throw new Exception();
		}

		for (int i = 0; i < Constants.FIELD_HEIGHT; i++) {
			System.out.print(field[col_index][i]+" ");
		
		}
		System.out.println("\n-----");
		return null;

	}
	
	

	public void printField() {
		for (int i = 0; i < Constants.FIELD_LENGTH; i++) {
			for (int j = 0; j < Constants.FIELD_HEIGHT; j++) {
				System.out.print(field[i][j]+" ");
			}
			System.out.println("");
		}
		System.out.println("\n---------");
	}
	
	public void randomize(){
		for (int i = 0; i < Constants.FIELD_LENGTH; i++) {
			for (int j = 0; j < Constants.FIELD_HEIGHT; j++) {
				Random randomizer = new Random();
				field[i][j] = randomizer.nextInt(9) + 1;
				
			}
		}
	}
	
	public void createValidSudoku(){
		SudokuGenerator.generateSudoku();
	}

	


}
